//管理用户数据相关

import {defineStore} from "pinia";
import {ref} from "vue";
import {loginAPI, loginOutAPI} from "@/apis/user.js";

export const useUserStore = defineStore('user', () => {
        //1.定义管理用户数据的state
        const userInfo = ref({})
        //2.定义获取数据的action
        const getUserInfo = async (data) => {
            const res = await loginAPI(data)
            console.log(res)
            userInfo.value = res.data.data
            return res
        }
        //3.清除数据的action
        const clearUserInfo = async (data) => {
            const res = await loginOutAPI(data)
            userInfo.value = {}
            return res
        }
        //4.以对象的格式把state和action返回出去
        return {
            userInfo,
            getUserInfo,
            clearUserInfo,
        }
    },
    {
        persist: true,
    },
)